﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class city_s_forum_reply : System.Web.UI.Page
{
    int no, reply;

    protected void Page_Load(object sender, EventArgs e)
    {


        no = int.Parse(Request["no"]);
        reply = int.Parse(Request["reply"]);

        ctp_lib.check_login(this.Page, "city_s_forum_reply.aspx?reply="+reply.ToString()+"&no=" + no.ToString());


        if (!this.IsPostBack)
        {
            ctpDataContext db = new ctpDataContext();
            ct_s_forum f = db.ct_s_forums.Single(p => p.no == reply);
            this.Label2.Text = f.title;

            ct_s_profile cts = db.ct_s_profiles.Single(p => p.valid == true && p.no == no && p.language_no == (int)Session["now_user_lang_no"]);

            this.HyperLink3.Text = cts.title;
            this.HyperLink3.NavigateUrl = "city_s.aspx?no=" + no.ToString().Trim();
            this.HyperLink2.Text = cts.ct_profile.title.Trim();
            this.HyperLink2.NavigateUrl = "city.aspx?no=" + cts.ct_no;

            this.HyperLink9.NavigateUrl = "city_s_forum.aspx?no=" + no.ToString();

            this.ViewState["ct_no"] = cts.ct_no;

        }


    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        ctpDataContext db = new ctpDataContext();
        ct_s_forum myf = new ct_s_forum();

        myf.addtime = DateTime.Now;
        myf.create_user_no = (int)Session["userno"];
        myf.ct_no = (int)this.ViewState["ct_no"];

        myf.ct_s_no = no;
        myf.last_post = DateTime.Now;
        myf.text = this.TextBox2.Text;
        //myf.title = this.TextBox1.Text;
        myf.reply_to = reply;



        ct_s_forum f = db.ct_s_forums.Single(p => p.no == reply);

        f.reply_amount += 1;
        f.last_post = DateTime.Now;
        

        db.ct_s_forums.InsertOnSubmit(myf);
        db.SubmitChanges();

        Response.Redirect("city_s_forum_show.aspx?no=" + reply.ToString());



    }

}
